import request from '../utils/request'
import type { RoleListParams, CreateRoleParams, UpdateRoleParams, RoleInfo } from '@/types/user'

export function fetchList(params: RoleListParams) {
  return request({
    url: '/role/v1/list',
    method: 'get',
    params
  })
}

export function createRole(data: CreateRoleParams) {
  return request({
    url: '/role/v1/create',
    method: 'post',
    data
  })
}

export function deleteRole(id: number) {
  return request({
    url: `/role/v1/delete/${id}`,
    method: 'delete'
  })
}

export function updateRole(data: UpdateRoleParams) {
  return request({
    url: '/role/v1/update',
    method: 'put',
    data
  })
}

export function getOneRole(id: number) {
  return request({
    url: `/role/v1/getOne/${id}`,
    method: 'get'
  })
}

/** 角色关联权限 */
export function createRolePermission(data: RoleInfo) {
  return request({
    url: '/v1/rolePermission/v1/create',
    method: 'post',
    data
  })
}

/** 更新角色关联权限 */
export function updateRolePermission(data: RoleInfo) {
  return request({
    url: '/v1/rolePermission/v1/update',
    method: 'put',
    data
  })
}

/** 删除角色关联权限 */
export function deleteRolePermission(data: { ids: number[] }) {
  return request({
    url: '/v1/rolePermission/v1/delete',
    method: 'delete',
    data
  })
}

/**根据角色ID查询权限关联列表 */
export function getOneRolePermission(id: number) {
  return request({
    url: `/v1/rolePermission/v1/byRole/${id}`,
    method: 'get'
  })
}
